package com.zpark.controller;

import com.zpark.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
//通过重写addInterceptors来重写配置拦截器
public class LoginInterceptorConfigurer implements WebMvcConfigurer {
    /**拦截器配置*/
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //创建拦截器对象
        HandlerInterceptor interceptor = new LoginInterceptor();

        //白名单
        List<String> patterns = new ArrayList<String>();
        patterns.add("/css/**");
        patterns.add("/fonts/**");
        patterns.add("/img/**");
        patterns.add("/js/**");
        patterns.add("/lib/**");
        patterns.add("/about-us.html");
        patterns.add("/contact-us.html");
        patterns.add("/index.html");
        patterns.add("/my.account.html");
        patterns.add("/simple-product.html");
        patterns.add("/address.html");
        patterns.add("/OrderAddress.html");
        patterns.add("/style.css");
        patterns.add("/districts/**");

//        registry.addInterceptor(interceptor).addPathPatterns("/**").excludePathPatterns(patterns);
    }
}
